

#ifndef NODEPERCENT_H
#define	NODEPERCENT_H

#include <QtGui>
#include "Node.h"

class NodePercent : public Node {

    Q_OBJECT

public:
    NodePercent()
    : Node(QString("percent"), 1, QString("%")) {
        // add the layout
        QHBoxLayout* layout = new QHBoxLayout(this);
        layout->setSpacing(1);
        layout->setContentsMargins(1, 1, 1, 1);

        // add the label
        QLabel* lab = new QLabel();
        lab->setText(getNodeValue());
        layout->addWidget(lab);
    }

    QString toCasString() const {
        Q_ASSERT_X(getSingleChild() != 0, "",
                "Could not find single child node.");
        Q_ASSERT_X(numChildren() == 1, "", "Expected one child.");

        QString str;
        str.append("(");
        if (getSingleChild()->getNodeType() == "empty") str.append("100");
        else str.append(getSingleChild()->toCasString());
        str.append("/100");
        str.append(")");
        return str;
    }

    QString toPrintString() const {
        Q_ASSERT_X(getSingleChild() != 0, "",
                "Could not find single child node.");
        Q_ASSERT_X(numChildren() == 1, "", "Expected one child.");

        QString str;
        if (getSingleChild()->getNodeType() == "empty") str.append("_");
        else str.append(getSingleChild()->toPrintString());
        str.append(getNodeValue());
        return str;
    }

    QString toParseString() const {
        Q_ASSERT_X(getSingleChild() != 0, "",
                "Could not find single child node.");
        Q_ASSERT_X(numChildren() == 1, "", "Expected one child.");

        QString str;
        str.append(getSingleChild()->toParseString());
        str.append(getNodeValue());
        return str;
    }

    int getInputPosition(bool& found) const {
        int counter = 0;
        if (not found) counter += getSingleChild()->getInputPosition(found);
        if (not found) counter += 1;
        return counter;
    }

    void setInputPosition(int& position) {
        Q_ASSERT_X(getSingleChild() != 0, "",
                "Could not find single child node.");
        Q_ASSERT_X(numChildren() == 1, "",
                "Expected one child.");

        if (position >= 0) getSingleChild()->setInputPosition(position);
        --position; // whatever this node takes

    }
};


#endif	/* NODEPERCENT_H */

